<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首付款管理</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<script type="text/javascript">
	var grid = null;
	var _mfrId;
	$(function () {
		initcombobox();//融资机构初始化 add by gengchunlan 20190606
		var _url = '<%=path%>/rfbase/fncprjfstpyinfo/initList.do' ;
	    $("#ligergrid1").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
  	            
	            { display: '项目名称', name: 'fncPrjNm', align:'center', width: 180 },
	            { display: '项目编号', name: 'fncPrjIdStr',align:'center', width: 150},
	            { display: '融资机构', name: 'fundRasInsNm', align:'center', width: 120 },
	            { display: '首付款状态', name: 'fncPrjStcd', align:'center', width: 80,render:changeStatus },
	            { display: '是否坐扣', name: 'wthrDdctFstPay',align:'center', width: 80,render:renderYesNo},
	            { display: '报价名称', name: 'fncScmNm', align:'center', width: 150 },
	            /* { display: '融资期数', name: 'fncTrm',align:'center', width: 80 }, */
	            { display: '融资经理', name: 'rlNm',align:'center', width: 80 },
	            { display: '实际付款时间', name: 'fstpyTm',align:'center', width: 100,render:renderDate },
	            { display: '操作', width: 280 ,height:'100px', align:'center',
	            	render: function (rowdata, rowindex, value){
	            		/* var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.fncPrjId+"'";
	                    h+=')">查看</a>'; */
	                    
	                    var h='<a class="sq-button-hasicon" href="javascript:showDetail(';
            				h+="'"+rowdata.fncPrjId+"'";
            				h+=')"><i class="sqBtnIco_4"></i>查看</a>';
	            		if(rowdata.fncPrjStcd == 3 && rowdata.fstpySt != 2 && rowdata.wthrDdctFstPay != 1){
		                    
		                    h+='<a class="sq-button-hasicon" href="javascript:modifyRow(';
            				h+="'"+rowdata.fncPrjId+"'";
            				h+=')"><i class="sqBtnIco_4"></i>修改</a>';
		                /*     h+='<a class="sq-button-hasicon" href="javascript:startFlow(';
            				h+="'"+rowdata.fncPrjId+"'";
            				h+=')"><i class="sqBtnIco_4"></i>申请付款</a>'; */
	            		}
	            		if((rowdata.fncPrjStcd == 3 || rowdata.fncPrjStcd == 4) && rowdata.fstpySt != 1 && rowdata.wthrDdctFstPay != 0){
		                    
	            			h+='<a class="sq-button-hasicon" href="javascript:noFirstPay(';
            				h+="'"+rowdata.fncPrjId+"'";
            				h+=')"><i class="sqBtnIco_4"></i>已坐扣</a>';
	            		}
	                	return h;
	            	}
	            },
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        rownumbers:true,
	        fixedCellHeight:false
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    
	});
  	
	//无首期费用 已坐扣
	function noFirstPay(_id){
		if(!_id)return;
		var _ids = [];
		_ids.push(_id);
		$.ligerDialog.confirm('确认该项目已坐扣?', function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/rfbase/fncprjfstpyinfo/noFirstPay.do?fncPrjId='+_id,
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
  	
	//修改方法
	function modifyRow(_id){
		if(!_id)return;
		Add_navTab('PrdSpl_2'+_id,'首付款修改','<%=path%>/rfbase/fncprjfstpyinfo/toAddPage.do?fncPrjId='+_id);
	}
	
	//查看详情
	function showDetail(_id){
		if(!_id)return;
		Add_navTab('PrdSpl_3'+_id,'首付款信息详情','<%=path%>/rfbase/fncprjfstpyinfo/toDetailPage.do?fncPrjId='+_id);
	}
	
	//发起审核流程
	function startFlow(_id){
		if(!_id)return;
		var modelTyp ="R014";//流程业务分类-再融资首付款审核
	//	alert(modelTyp);
		if(StringUtils.isEmpty(modelTyp)){
			console.log("modelTyp is null");
			return;
		}
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
            width: 700,
            height:400,
            title : '请选择要发起的流程',
            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ],
            onClose: function () {
            	var json = flowDialog._DATA;
            	console.log(json);
            	if(!json){
                	return;
            	}
            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
        		$.ajax({
            		type: 'post',
            		dataType:'json',
            		data:{
            			fncPrjId:_id,
            			procDefKey:json.procDefKey,
            			procDefId:json.procDefId,
            			procNo:json.procNo
            		},
            		url: '<%=path%>/rfbase/fncprjfstpyinfo/addFlowStart.do',
            		success:function(msg){
            			wait_dialog.close();
            			 if(msg.success == 1){
          					 UIUtils.alertSuccessHold1(msg.info);
           				 	 grid.reload();
	           			 }else{
	          				UIUtils.alertErrorHold1(msg.info);
	           			 }
            		}
            	});
            }
        });
	}	
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	
	//显示是否
	function renderYesNo(rowdata, index, value){
		var dateStr = "";
		if(0 == value){
			dateStr = "否";
		}
		if(1 == value){
			dateStr = "是";
		}
		if(2 == value){
			dateStr = "是/否";
		}
		return dateStr;
	}
	//改变状态的显示
	function changeStatus(rowdata, index, value){
		if(value==3){
			value="未付款";
		}else if(value==4){
			value="已申请";
		}else{
			value="已付款";
		}
		return value;
	}
	
	//清空按钮事件
	function clearBtn(){
		 $("#resetBtn").click();  //重置 input-text
		 var form = new liger.get("searchBar");
		 form.setData({  //重置select等特殊表单
		    "fncInsId":"",
		    "fncScmId":"",
		    "fncFstpyStcd":"",
		    "fncPrjNm":"",
		    "wthrDdctFstPay":""
		  });
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	 //初始化融资机构 by gengchunlan 20190606
	 var frilist = [];
	<c:if test="${not empty frilist}"> frilist = ${frilist}; </c:if>
	 function initcombobox(){
		 var combobox=  $("#fncInsId").ligerComboBox({
   	     data:frilist,
            selectBoxWidth: 270,
            selectBoxHeight: 150,
            valueField: "id",
            textField: "fundRasInsNm",
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            }
           });
	 }//end 
</script>

<body class="iframeBody">
	<div class="Wrapper">
		<div class="searchArea">
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					
					<div class="fieldBox">
						<div class="label">融资机构：</div>
						<%-- <div class="field">
							<select name="fncInsId" id="fncInsId" data-value=" ">
								<option value=" " seleted>请选择</option>
								<c:forEach items="${fundRasInsNmList }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div> --%>
						<div class="field">
	                    <input name="fncInsId" id="fncInsId" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
	                	</div>
	                	<div style="display: none">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">融资报价：</div>
						<div class="field">
							<select name="fncScmId" id="fncScmId" data-value=" ">
								<option value=" " seleted>请选择</option>
								<c:forEach items="${fncScmNmList }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">项目名称：</div>
						<div class="field">
							<input name="fncPrjNm" id="fncPrjNm" type="text" class="ui-textbox" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">是否坐扣：</div>
						<div class="field">
							<select name="wthrDdctFstPay" id="wthrDdctFstPay" data-value=" ">
								<option value=" " seleted>请选择</option>
								<c:forEach items="${wthrDdctFstPayList }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">首付款状态：</div>
						<div class="field">
							<select name="fncFstpyStcd" id="fncFstpyStcd" data-value=" ">
								<option value=" " seleted>请选择</option>
								<option value="3" seleted>未付款</option>
								<option value="4" seleted>已申请</option>
								<option value="5,6,7,8,9,10,11,12,13" seleted>已付款</option>
							</select>
						</div>
					</div>
					<div class="clearFix"></div>
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round" onclick="clearBtn();">清空</span>
						<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide" />
					</div>
			</form>
		</div>
	</div>
	<div id="ligergrid1" class="sq-grid"></div>


</body>
</html>
